package org.cx.oa.web.struts.actions;

import java.util.List;

import org.cx.oa.dao.impl.CongfigCommunicationInfoImpl;
import org.cx.oa.dao.impl.ConnectionTypeInfoImpl;
import org.cx.oa.entity.CongfigCommunication;
import org.cx.oa.entity.ConnectionType;
import org.cx.oa.entity.Employee;
import org.cx.oa.entity.UserBasicInfomation;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class SequenceCommunicationAction extends ActionSupport {

	public ConnectionType getCt() {
		return ct;
	}

	public void setCt(ConnectionType ct) {
		this.ct = ct;
	}

	public List<ConnectionType> getCtList() {
		return ctList;
	}

	public void setCtList(List<ConnectionType> ctList) {
		this.ctList = ctList;
	}

	public Integer getId() {
		return Id;
	}

	public void setId(Integer id) {
		Id = id;
	}

	public CongfigCommunication getCfc() {
		return cfc;
	}

	public void setCfc(CongfigCommunication cfc) {
		this.cfc = cfc;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<CongfigCommunication> congfigCommunications;
	private CongfigCommunicationInfoImpl cfcDao = new CongfigCommunicationInfoImpl();
	private ConnectionTypeInfoImpl ctDao = new ConnectionTypeInfoImpl();
	private ConnectionType ct;
	private List<ConnectionType> ctList;
	private Integer Id;
	private CongfigCommunication cfc = new CongfigCommunication();
	private ActionContext context=ActionContext.getContext();
	private UserBasicInfomation users = (UserBasicInfomation) context.getSession().get("user");
	private Employee employee = new Employee();
	
	public List<CongfigCommunication> getCongfigCommunications() {
		return congfigCommunications;
	}

	public void setCongfigCommunications(
			List<CongfigCommunication> congfigCommunications) {
		this.congfigCommunications = congfigCommunications;
	}
	
	public String operationJsp(){
		
		ctList = ctDao.findAll();
		congfigCommunications = cfcDao.selectCongfigC(users.getUserId());
		//congfigCommunications = cfcDao.findAll();
		return SUCCESS;
	}
	
	public String update(){
		
		cfc.setConnectionType(ct);
		employee.setId(users.getUserId());
		cfc.setEmployee(employee);
	    cfcDao.update(cfc);
	    operationJsp();
		return SUCCESS;
	}
	
	public String updateJsp(){
		
		cfc = cfcDao.findById(Id);
		ctList = ctDao.findAll();
		return "update";
	}
	
	public String delete(){
		
		cfc = cfcDao.findById(Id);
		cfcDao.delete(cfc);
		return "delete";
	}
	
	public String add(){
		
		cfc.setConnectionType(ct);
		employee.setId(users.getUserId());
		cfc.setEmployee(employee);
		cfcDao.save(cfc);
		operationJsp();
		return "successAdd";
	}
	
	public String addRelationType(){
		
		ctDao.save(ct);
		return "successAdd";
	}
	
	public String addRelationTypeJsp(){
		
		return "addRelation";
	}
	
	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
}
